#include "precompiled.h"
#include "characterfactory.h"
using namespace weo::engine::character;
CharacterFactory *CharacterFactory::s_Factory = NULL;
void* CharacterFactory::callFactory(std::string classname, std::string buildname)
{
    std::map<std::string,std::map<std::string,CharacterFactoryFn*>>::iterator it = m_ClassBuildMap.find(classname);
    if(it != m_ClassBuildMap.end())
    {
        std::map<std::string,CharacterFactoryFn*>::iterator it2 = it->second.find(buildname);
        if(it2 != it->second.end())
        {
            return it2->second();
        }
    }
    return NULL;
}
void CharacterFactory::registerClassBuild(std::string classname, std::string buildname, CharacterFactoryFn* pFunction)
{
    std::map<std::string,std::map<std::string,CharacterFactoryFn*>>::iterator it = m_ClassBuildMap.find(classname);
    if(it != m_ClassBuildMap.end())
    {
        std::map<std::string,CharacterFactoryFn*>::iterator it2 = it->second.find(buildname);
        if(it2 == it->second.end())
        {
            it->second[buildname] = pFunction;
        }
        else return;
    }
    else
    {
        std::map<std::string,CharacterFactoryFn*> map;
        map[buildname] = pFunction;
        m_ClassBuildMap[classname] = map;
    }
}
CharacterFactory* CharacterFactory::getInstance()
{
    if(!s_Factory)
    {
        s_Factory = new CharacterFactory();
    }
    return s_Factory;
}